package com.qfedu.yanglao20admin.evaluate.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.entity.evaluate.Evaluate;
import com.qfedu.yanglao20.entity.evaluate.EvaluateConfig;
import com.qfedu.yanglao20admin.evaluate.service.EvaluateConfigService;
import com.qfedu.yanglao20admin.evaluate.service.EvaluateService;
import com.qfedu.yanglao20admin.evaluate.vo.EvaluateConfigVO;
import com.qfedu.yanglao20admin.evaluate.vo.EvaluateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Evaluate)表控制层
 *
 * @author makejava
 * @since 2023-05-05 19:47:42
 */
@Api(tags = "评价管理")
@RestController
@RequestMapping("evaluate")
public class EvaluateController {
    /**
     * 服务对象
     */
    @Resource
    private EvaluateService evaluateService;
    @Resource
    private EvaluateConfigService evaluateConfigService;

    /**
     * 分页查询
     *
     * @param evaluate    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping("evaluate/page")
    @ApiOperation(value = "评论列表")
    public ResponseEntity<Page<EvaluateVO>> queryByPage(EvaluateVO evaluate) {
        return ResponseEntity.ok(this.evaluateService.queryByPage(evaluate));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "评论列表查看")
    @GetMapping("{id}")
    public CommonResult<EvaluateVO> queryById(@PathVariable("id") Integer id) {
        Evaluate evaluate = evaluateService.queryById(id);

        return CommonResult.success(evaluate);
    }


    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @ApiOperation("评论列表删除")
    @DeleteMapping("delete")
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.evaluateService.deleteById(id));
    }

    @GetMapping("config")
    @ApiOperation("评价配置")
    public CommonResult<EvaluateConfig> selectList() {
        return CommonResult.success(evaluateConfigService.selectAll());
    }

    @ApiOperation("评价配置分页")
    @GetMapping("config/page")
    public CommonResult<Page<EvaluateConfigVO>> selectPage(EvaluateConfigVO evaluateConfigVO) {
        return CommonResult.success(evaluateConfigService.queryByPage(evaluateConfigVO));
    }

    @ApiOperation("评价配置查看")
    @GetMapping("config/ById")
    public CommonResult<EvaluateConfig> SelectById(Integer id) {
        return CommonResult.success(evaluateConfigService.queryById(id));
    }

    @ApiOperation("评价配置编辑")
    @PostMapping("update/evalute")
    public CommonResult updateEvalute(EvaluateConfig evaluateConfig) {
        evaluateConfigService.update(evaluateConfig);
        return CommonResult.success();
    }

    @ApiOperation("评价配置添加")
    @PostMapping("insert/evalute")
    public CommonResult insertEvalute(EvaluateConfig evaluateConfig) {
        evaluateConfigService.insert(evaluateConfig);
        return CommonResult.success();
    }

    @ApiOperation("评价配置删除")
    @DeleteMapping("delete/evaluteConfig")
    public CommonResult deleteEvaluteConfig(Integer id) {
        evaluateConfigService.deleteById(id);
        return CommonResult.success();
    }
}

